package com.joker;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 代码生成
 * @Author JokerKS
 * @Date 2021/12/25 22:17
 * @Version 1.0
 */
public class JokerCode {

	public static void main(String[] args) {
		List<String> tables = new ArrayList<>();
		tables.add("user");

		FastAutoGenerator.create("你自己的数据库url","数据库用户名","密码")
				.globalConfig(builder -> {
					builder.author("Joker")               //作者
							.outputDir(System.getProperty("user.dir")+"\\src\\main\\java")    //输出路径(写到java目录)
							.enableSwagger()           //开启swagger
							.commentDate("yyyy-MM-dd")
							.fileOverride();            //开启覆盖之前生成的文件

				})
				.packageConfig(builder -> {
					builder.parent("com.joker.xp")//生成到的目录，下面是各个模块
							.moduleName("practice")
							.entity("entity")
							.service("service")
							.serviceImpl("serviceImpl")
							.controller("controller")
							.mapper("mapper")
							.xml("mapper")
							.pathInfo(Collections.singletonMap(OutputFile.mapperXml,System.getProperty("user.dir")+"\\src\\main\\resources\\mapper"));
				})
				.strategyConfig(builder -> {
					builder.addInclude(tables)
							.addTablePrefix("p_")
							.serviceBuilder()
							.formatServiceFileName("%sService")
							.formatServiceImplFileName("%sServiceImpl")
							.entityBuilder()
							.enableLombok()
							.logicDeleteColumnName("deleted")
							.enableTableFieldAnnotation()
							.controllerBuilder()
							.formatFileName("%sController")
							.enableRestStyle()
							.mapperBuilder()
							.superClass(BaseMapper.class)
							.formatMapperFileName("%sMapper")
							.enableMapperAnnotation()
							.formatXmlFileName("%sMapper");
				})
				.templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
				.execute();
	}

}
